<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .box{
            width: 50px;
            height: 50px;
            border-radius: 50%;
            background-color: green;
            position: absolute;
            left: 0;
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
<script>
    const box = document.querySelector('.box');
    let dis = 0;
    // let interval = setInterval(() =>{
    //     box.style.left = ++dis +'px';
    //     if(dis >= 500){
    //         clearInterval(interval);
    //     }
    // },6);

    // 电脑设置过显示频率
    //requestAnimationFrame
    //界面更流畅
    function animation(){
        requestAnimationFrame(function(){
            // console.log('-----');
            box.style.left = ++dis + 'px';
            if(dis < 500){
                animation();//递归
            }                
        });
    }
    animation();
</script>
</html>